<?php


namespace Tbf\Bundle\RouteBundle\Matcher;


use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
use Tbf\Bundle\RouteBundle\Matcher\MatcherInterface;

class RedirectMatcher implements MatcherInterface{
    protected $from_url;
    protected $to_url;
    public function __construct($from_url,$to_url){
        $this->from_url = $from_url;
        $this->to_url = $to_url;
    }
    /**
     * @param Request $request
     * @return \Symfony\Component\HttpFoundation\Response
     */
    public function match(Request $request)
    {
        if ($request->getPathInfo()!==$this->from_url){
            return null;
        }
        return new RedirectResponse($this->to_url);
    }
}